public class MyBinaryTree {
    static class TreeNode {
        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }

    public TreeNode root;
    public int TreeSize;
    public TreeNode createTree() {
        TreeNode A = new TreeNode('A');
        TreeNode B = new TreeNode('B');
        TreeNode C = new TreeNode('C');
        TreeNode D = new TreeNode('D');
        TreeNode E = new TreeNode('E');
        TreeNode F = new TreeNode('F');
        TreeNode G = new TreeNode('G');
        TreeNode H = new TreeNode('H');
        A.left = B;
        A.right = C;
        B.left = D;
        B.right = E;
        C.left = F;
        C.right = G;
        D.left = H;
        root = A;
        return root;
    }
    public void size(TreeNode root) {
        if (root == null) {
            return;
        }
        TreeSize++;
        size(root.left);
        size(root.right);
    }


    /**
     * 获取节点的个数：子问题的思路
     *
     * @param root
     * @return
     */
    public int size2(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int leftsize = size2(root.left);
        int rightsize = size2(root.right);
        return leftsize + rightsize + 1;
    }


    /*
     获取叶子节点的个数：遍历思路
     */
    public static int leafSize = 0;

    public void getLeafNodeCount1(TreeNode root) {
        if(root == null){
            return;
        }
        if(root.left == null && root.right == null){
            leafSize++;
        }
        getLeafNodeCount1(root.left);
        getLeafNodeCount1(root.right);
    }

    /*
     获取叶子节点的个数：子问题
     */
    public int getLeafNodeCount2(TreeNode root) {
        if(root == null){
            return 0;
        }
        if(root.left == null && root.right == null){
            return 1;
        }
        int leftLeaf = getLeafNodeCount2(root.left);
        int rightLeaf = getLeafNodeCount2(root.right);
        return leftLeaf + rightLeaf;
    }

    /*
    获取第K层节点的个数
     */
    public int getKLevelNodeCount(TreeNode root, int k) {
    }

    /*
     获取二叉树的高度
     时间复杂度：O(N)
     */
    public int getHeight(TreeNode root) {
        if(root == null) {
            return 0;
        }
        int lefthight = getHeight(root.left);
        int righthight = getHeight(root.right);
        return (lefthight>righthight)?(lefthight+1):(righthight+1);
    }


    // 检测值为value的元素是否存在
    public TreeNode find(TreeNode root,int val) {
        if(root == null) {
            return null;
        }
        if(root.val == val){
            return root;
        }
        TreeNode left = find(root.left,val);
        if(left != null){
            return root;
        }
        TreeNode right = find(root.right,val);
        if(right != null){
            return root;
        }
        return null;
    }

    //层序遍历
    public void levelOrder(TreeNode root) {

    }


    // 判断一棵树是不是完全二叉树
    public boolean isCompleteTree(TreeNode root) {
        return true;

    }
}